package micro

import "context"

type Option func(o *Options)
type serviceKey struct{}
type Service interface {
	Name() string
	Init(...Option)
	Options() Options
	Client() client.Client
	Server() server.Server
	Run() error
	String() string
}

type Function interface {
	Service
	Done() error
	Handler(v interface{}) error
	Subscribe(topic string, v interface{}) error
}

type Event interface {
}
type Publisher Event

var (
	HeaderPrefix = "Micro-"
)

func NewService(opts ...Option) Service {
	return newService(opts...)
}

func FromContext(ctx context.Context) (Service, bool) {
	s, ok := ctx.Value(serviceKey{}).(Service)
	return s, ok
}

func NewContext(ctx context.Context, s Service) context.Context {
	return context.WithValue(ctx, serviceKey{}, s)
}